clear;
input_layer_size = 20 * 20;
num_labels = 10;
load('ex3data1.mat');
m = size(X, 1); % m = 5000

rand_indices = randperm(m);
sel = X(rand_indices(1:4), :);
displayData(sel);
theta_t = [-2; -1; 1; 2];
X_t = [ones(5, 1), reshape(1:15, 5, 3) / 10];
y_t = ([1; 0; 1; 0; 1] >= 0.5);
lambda_t = 3;
[J grad] = lrCostFunction(theta_t, X_t, y_t, lambda_t);

fprintf('\nCost: %f\n', J);
fprintf('Expected cost: 2.534819\n');
fprintf('Gradients:\n');
fprintf(' %f \n', grad);
fprintf('Expected gradients:\n');
fprintf(' 0.146561\n -0.548558\n 0.724722\n 1.398003\n');

% X = 1 - X;
% X(1, :)
lambda = 0.1;
[all_theta] = oneVsAll(X, y, num_labels, lambda);

pred = predictOneVsAll(all_theta, X);
fprintf('\nTraining Set Accuracy: %f\n%', sum(pred == y) / length(y) * 100);

% picture_rgb = imread('6.png');
% % size(picture_rgb)
% picture_gray = rgb2gray(picture_rgb);
% size(picture_gray);
% imshow(picture_gray);
% feature = reshape(picture_gray, 1, 400)
% feature = double(feature) / max(double(feature))
% num_predict(all_theta, double(feature))
%fprintf('\nthe number in picture is: %f\n%', );
